package com.example.mygame.controller;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.mygame.R;
import com.example.mygame.pojo.User;
import com.example.mygame.service.SqliteUtils;

import java.util.List;

public class Mine extends AppCompatActivity {

    private TextView userName;
    private TextView nick;
    private TextView age;
    private TextView sex;
    private TextView phone;
    private Button modifyUserInfo;
    private Button modifyPassword;
    private Button addFriend;
    private Button showFriend;
    private Integer userId;

    private SqliteUtils sqliteUtils;

    Intent intent = new Intent();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);

        sqliteUtils = new SqliteUtils(this);

        userName = findViewById(R.id.userName);
        nick = findViewById(R.id.nick);
        age = findViewById(R.id.age);
        sex = findViewById(R.id.sex);
        phone = findViewById(R.id.phone);
        modifyUserInfo = findViewById(R.id.modify_user_info);
        modifyPassword = findViewById(R.id.modify_password);
        addFriend = findViewById(R.id.addFriend);
        showFriend = findViewById(R.id.myFriend);

        Intent getDataIntent = getIntent();

        String getUserName = getDataIntent.getStringExtra("userName");

        List<User> userList = sqliteUtils.queryFromDbByName(getUserName);


        for (User user : userList) {
            nick.setText("昵称："+user.getNick());
            userName.setText("用户名："+user.getName());
            age.setText("年龄："+user.getAge());
            sex.setText("性别："+user.getSex());
            phone.setText("手机："+user.getPhone());
        }

        modifyUserInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Mine.this, ModifyUserInfo.class);
                Bundle bundle = new Bundle();
                bundle.putString("userName",getUserName);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });

        modifyPassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Mine.this, ModifyPassword.class);
                Bundle bundle = new Bundle();
                bundle.putString("userName",getUserName);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });

        addFriend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Mine.this, AddFriend.class);
                Bundle bundle = new Bundle();
                bundle.putString("userName", getUserName);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });



        showFriend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Mine.this, ShowFriend.class);
                Bundle bundle = new Bundle();
                bundle.putString("userName", getUserName);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });




    }
}